package com.htc.model.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.htc.constants.Constants;
import com.htc.model.dto.SpaChildDTO;

public class SpaChildModel {
	public static SpaChildModel instance;

	public static SpaChildModel getInstance() {
		if (instance == null)
			instance = new SpaChildModel();
		return instance;
	}

	public boolean checkDB(Context context, String id) {
		boolean flag = false;
		String sql = "SELECT spa_section_id FROM " + Constants.TBL_SPA_SECTION
				+ " where spa_section_id='" + id + "'";
		DBHelper db = DBHelper.getInstance(context);
		Cursor c = db.Excutequery(sql);
		while (c.moveToNext()) {
			flag = true;
			break;
		}
		c.close();
		db.close();
		return flag;
	}

	public boolean insertSpachil(SpaChildDTO spac, Context context) {
		boolean flag = false;
		if (!checkDB(context, spac.getSecId())) {
			String DATABASE_TABLE = Constants.TBL_SPA_SECTION;
			ContentValues values = new ContentValues();
			values.put("spa_section_id", spac.getSecId());
			values.put("spa_section_title", spac.getSecTitle());
			values.put("spa_section_description", spac.getSpaDesc());
			values.put("spa_category_id", spac.getSpaCatId());
			values.put("spa_section_pakage_price", spac.getSpaPackagePrice());
			values.put("spa_section_time_duration", spac.getSpaTimeDuration());
			values.put("spa_section_title_ar", spac.getSecTitleAr());
			values.put("spa_section_description_ar", spac.getSpaDescAr());
			DBHelper db = DBHelper.getInstance(context);
			flag = db.ExcuteInsert(null, DATABASE_TABLE, values);
			db.close();
		}

		return flag;
	}

	public boolean updateSpachil(SpaChildDTO spac, Context context) {
		boolean flag = false;

		String DATABASE_TABLE = Constants.TBL_SPA_SECTION;
		String where = "spa_section_id='" + spac.getSecId() + "'";
		ContentValues values = new ContentValues();
		values.put("spa_section_title", spac.getSecTitle());
		values.put("spa_section_description", spac.getSpaDesc());
		values.put("spa_category_id", spac.getSpaCatId());
		values.put("spa_section_pakage_price", spac.getSpaPackagePrice());
		values.put("spa_section_time_duration", spac.getSpaTimeDuration());
		values.put("spa_section_title_ar", spac.getSecTitleAr());
		values.put("spa_section_description_ar", spac.getSpaDescAr());
		DBHelper db = DBHelper.getInstance(context);
		flag = db.ExcuteUpdate(null, DATABASE_TABLE, values, where, null);
		db.close();
		return flag;
	}

	public void deleteSpachil(SpaChildDTO spac, Context context) {
		String sql = "spa_section_id='" + spac.getSecId() + "'";
		DBHelper db = DBHelper.getInstance(context);
		String DATABASE_TABLE = Constants.TBL_SPA_SECTION;
		db.deleteTable(DATABASE_TABLE, sql);
		db.close();
	}
}
